package cn.huiyunche.base.service.interfaces.impl;

import cn.huiyunche.base.service.interfaces.DWaybillLogisticsService;
import cn.huiyunche.base.service.mappers.DWaybillLogisticsMapper;
import cn.huiyunche.base.service.model.DWaybillLogistics;
import cn.huiyunche.base.service.model.DWaybillLogisticsExample;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @FileName: cn.huiyunche.app.service.interfaces.impl
 * @Description: Description
 * @author: Aaron
 * @date: 2016/12/27 下午3:09
 */
@Service
public class DWaybillLogisticsServiceImpl implements DWaybillLogisticsService {

    private static final Logger LOGGER = LoggerFactory.getLogger(DWaybillLogisticsServiceImpl.class);

    @Autowired
    private DWaybillLogisticsMapper dWaybillLogisticsMapper;

    @Override
    public List<DWaybillLogistics> getListByDWaybillId(Long dWaybillId) {
        LOGGER.info("getListByDWaybillId param : {}", dWaybillId);
        if (null == dWaybillId) {
            LOGGER.error("getListByDWaybillId param dWaybillId must not be null");
            throw new IllegalArgumentException("运单主键不能为空");
        }

        DWaybillLogisticsExample example = new DWaybillLogisticsExample();
        example.createCriteria().andWaybillIdEqualTo(dWaybillId);
        example.setOrderByClause(" create_time DESC ");

        return dWaybillLogisticsMapper.selectByExample(example);
    }

    @Override
    public Long add(DWaybillLogistics logistics) {
        LOGGER.info("add param : {}", logistics);
        if (null == logistics) {
            LOGGER.error("add param logistics must not be null");
            throw new IllegalArgumentException("运单物流信息不能为空");
        }

        dWaybillLogisticsMapper.insertSelective(logistics);

        return logistics.getId();
    }
}
